package com.xuhj.export;

import com.xuhj.common.ExcelFileType;
import com.xuhj.domain.Person;
import com.xuhj.export.factory.ExcelFactory;
import org.springframework.core.io.ClassPathResource;

import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TestExport {
    public static void main(String[] args) throws IOException {
        FileOutputStream out = null;
        List<Person> list = new ArrayList<>();
        File file = null;
        //生成数据
        for (int i = 0; i < 100; i++) {
            int num = i + 1;
            Person person = new Person();
            person.setId(num);
            person.setName("张三-"+(num));
            person.setAddress("花园路"+num+"号"+(int)Math.ceil(Math.random()*10)+"号楼");
            person.setAge(i+18);
            person.setHobby("洗脸刷牙打DOTA");
            person.setJob("程序员");
            person.setBirthday(new Date());
            person.setSex('男');
            person.setPhone(4536456498778789123L);
            person.setWorked(true);
            list.add(person);
        }

         try{
             // TODO 文件需要放在当前模块的Resources目录下
             out = new FileOutputStream(new ClassPathResource("export.xlsx").getPath());
             ExcelFactory.createExcel(list, ExcelFileType.XSSF).write(out);
             } catch (Exception e) {
                 e.printStackTrace();
             }finally {
             out.close();
//             Desktop.getDesktop().open(file);
         }

    }
}
